import socket
import os
from DesModule import des_encrypt, des_descrypt
host = "192.168.56.1"
port = 8000
Address = (host, port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 8000))
if os.path.exists("client_send.txt"):
    file1 = open("client_send", "r+")
else:
    file1 = open("client_send", "w+")
file1.write("To be or not to be,that's a question. ")
file1.seek(0)
data1 = file1.readline()
data1 = data1.encode()
cryptostring = des_encrypt(data1, "12345678")
s.sendall(cryptostring.encode())
data = s.recv(1024)
message1 = des_descrypt(data, "12345678")
print("从服务器接收的数据为:", message1)
if os.path.exists("client_receive.txt"):
    file2 = open("client_receive.txt", "r+")
else:
    file2 = open("client_receive.txt", "w+")
file2.write(message1)
file2.close()
s.close()
